from selenium.webdriver.common.by import By

from seleniums.base_page.basepage import BasePage
from seleniums.page.image import ImagePage


class MainPage(BasePage):
    _base_url = "http://www.baidu.com"

    # 图片元素定位
    image = (By.CSS_SELECTOR,'#s-top-left>a:nth-child(6)')

    # 跳转到图片搜索页
    def go_to_image(self):
        self.find(self.image[0],self.image[1]).click()
        # 因为点击会打开一个新窗口，所以我们在这里切换窗口
        current_handles = self._driver.current_window_handle
        for handle in self._driver.window_handles:
            if current_handles != handle:
                self._driver.switch_to.window(handle)

        return ImagePage(self._driver)



